Skip to content

feat: reference sources and the template gate's @responseRef reply check, all six ports - #648

Merged
dmealing merged 7 commits into
mainfrom
fm/mo-reply-type-c0
Nov 25, 2026
Merged

dmealing merged 7 commits into
mainfrom
fm/mo-reply-type-c0

Conversation

@dmealing

@dmealing dmealing commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • Reference sources (all ports): a sources entry may carry "reference": true (Maven: <loader><referenceSources>); its files load into the same root so @responseRef and other references resolve, and a top-level node declared only in reference files becomes a reference node that no generator emits — excluded at the codegen selection choke point in TypeScript, C#, Java/Kotlin and Python, while a local prompt keeps its parser, output-format fragment and extractor. A template.* declared only in reference sources is refused with ERR_REFERENCE_SOURCE_TEMPLATE (at load time in Java). Pinned by the new fixtures/reference-source-conformance/ corpus (6 cases) plus 2 new source-resolution-conformance cases (now 30).
  • The template gate reads @responseRef (all ports): ERR_RESPONSE_UNRESOLVED (error) when a responding prompt's reply type resolves to no value shape with a readable field, and ERR_RESPONSE_TAG_UNDECLARED (warning) when an xml prompt's @requiredTags entry names neither the reply type's short name nor any field in its tree; attributes are read through the resolving accessors (ADR-0039). Pinned by the new fixtures/response-verify-conformance/ corpus (7 cases).
  • Rust template-gate parity: cargo meta verify --templates now exists — a Mustache body verify in metaobjects-render (verify module, held to all 45 verify-conformance cases), bodies under prompts/ (--prompts <dir>), a bare verify running the codegen, template and rules gates, and a Jinja body refused with ERR_TEMPLATE_ENGINE_UNSUPPORTED; ADR-0065 Amendment 6 records it. Docs updated to 48 shared corpora (AGENTS.md, docs/CONFORMANCE.md, showcase payload), and the three changelog entries live in changelog.d/ fragments.
Validation

Risk Assessment

⚠️ Medium: I found no source defect or intent contradiction in the five ports or the Rust template gate. The diff is large and cross-cutting, though (101 files, new loader and generator selection semantics, and a bare Rust verify that now fails on a template project with no prompts directory), and I did not run any tests.

Testing

Broad regression came from the configured command scripts/ci-local.sh --affected --strict-toolchains, which ran green at the target commit; this turn changed no source or test files, so it was not re-run. On top of that I drove three scenarios against the real products: the TypeScript meta gen/meta verify --templates CLI (dist build) and the Rust cargo-meta binary, each in a disposable fixture project under a temporary .mo-scenario/ directory in the worktree (deleted afterwards; worktree clean). The reference-source scenario reproduced the adopter's measured blocker first (load refusal ERR_INVALID_TEMPLATE without the flag), then showed the fix end-to-end: @responseRef resolves, the reply types emit no code, and the local prompt's parser still names them; the ERR_REFERENCE_SOURCE_TEMPLATE guard refused a prompt declared only in a reference source. The TS and Rust verify runs confirmed the reply gate's error/warning severities and, in Rust, the new gate itself plus the Jinja refusal and a bare verify running the gate. All passed. No UI surface exists in this change, so evidence is CLI transcripts (4 log files in the evidence directory). Nothing was left running.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
meta gen (TypeScript CLI) with a reference: true source: the prompt's @responseRef resolves against the reply types another run owns, no code is emitted for those reference nodes, the local prompt s… ✅ pass live local run evidence (not published)
meta verify --templates (TypeScript CLI) reply check: a resolving xml reply with tags naming the reply and its nested fields passes clean; a @responseRef whose reply type has no readable field fails t… ✅ pass live local run evidence (not published)
Rust parity: cargo-meta meta verify --templates on a disposable fixture runs the previously-absent template gate with the reply check (clean pass; ERR_RESPONSE_UNRESOLVED exit 1), refuses a Jinja body… ✅ pass live local run evidence (not published)
Evidence: S1 — meta gen reference sources: control refusal, reference happy path (parser names reply type, no reference-node files), ERR_REFERENCE_SOURCE_TEMPLATE guard

meta: failed to load metadata: ERR_INVALID_TEMPLATE: template "SupportAnswerPrompt" @responseRef "acme::support::SupportAnswer" does not resolve … generated/SupportAnswerPrompt.response.ts generated/SupportRequest.ts import type { SupportAnswer } from "./SupportAnswer.js"; meta: failed to load metadata: ERR_REFERENCE_SOURCE_TEMPLATE: template "acme::support::SupportAnswerPrompt" is declared only in a reference source …

## S1 control: gen WITHOUT reference source (adopter blocker as measured)
meta: failed to load metadata: ERR_INVALID_TEMPLATE: template "SupportAnswerPrompt" @responseRef "acme::support::SupportAnswer" does not resolve to an object.value or sourceless object.projection at root
  in meta.prompts.json at $['metadata.root'].children[1]['template.prompt']
exit=1

## S1 happy: replies/ declared reference:true
gen[2]{file,status}:
  generated/SupportRequest.ts,new
  generated/SupportAnswerPrompt.response.ts,new
summary: 2 written
help[1]: typecheck the generated code with `npx tsc`
antiPatterns:
  status: ran
  total: 0
  rows: []
exit=0

## generated tree:
generated/SupportAnswerPrompt.response.ts
generated/SupportRequest.ts

## parser names the reference reply type:
5:import type { SupportAnswer } from "./SupportAnswer.js";
7:const SupportAnswerPromptSchema = z.object({
14:export type SupportAnswerPromptValidationError = z.ZodError;
17: * Parse an LLM response into a typed SupportAnswer. The reply must BE the JSON document (a

## S1 guard: the prompt itself declared only in the reference source
meta: failed to load metadata: ERR_REFERENCE_SOURCE_TEMPLATE: template "acme::support::SupportAnswerPrompt" is declared only in a reference source (ref:metaobjects/replies/meta.replies.json). A reference source holds shapes another run generates; declare the prompt in one of the project's own sources, where its parser and payload are generated.
  in ref:metaobjects/replies/meta.replies.json at $['metadata.root'].children[2]['template.prompt']
exit=1
Evidence: S2 — meta verify --templates reply gate (TS): clean / ERR_RESPONSE_UNRESOLVED error / ERR_RESPONSE_TAG_UNDECLARED warnings

meta: [SupportAnswerPrompt] (reply) ERR_RESPONSE_UNRESOLVED: acme::support::EmptyAnswer meta: meta verify — 1 drift error(s) across 1 template(s). meta: [SupportAnswerPrompt] (reply) ERR_RESPONSE_TAG_UNDECLARED: answer meta: [SupportAnswerPrompt] (reply) ERR_RESPONSE_TAG_UNDECLARED: confidence meta: meta verify — 1 template(s) clean (2 warning(s)).

## S2 clean: xml reply resolves, tags name reply + its fields
meta: meta verify — 1 template(s) clean (2 warning(s)).
meta: meta verify — not run: schema (--db <url>), codegen (--codegen), deps (--deps), replay (--replay)
  templates,true,true
exit=0

## S2 error: @responseRef names EmptyAnswer (no fields)
meta: [SupportAnswerPrompt] (reply) ERR_RESPONSE_UNRESOLVED: acme::support::EmptyAnswer
meta: meta verify — 1 drift error(s) across 1 template(s).
meta: meta verify — not run: schema (--db <url>), codegen (--codegen), deps (--deps), replay (--replay)
exit=1

## S2 warning: xml @requiredTags name answer/confidence which the reply does not declare
meta: [SupportAnswerPrompt] (reply) ERR_RESPONSE_TAG_UNDECLARED: answer
meta: [SupportAnswerPrompt] (reply) ERR_RESPONSE_TAG_UNDECLARED: confidence
meta: meta verify — 1 template(s) clean (2 warning(s)).
meta: meta verify — not run: schema (--db <url>), codegen (--codegen), deps (--deps), replay (--replay)
exit=0
Evidence: S2 clean rerun — xml reply with tags naming the reply and nested source.url, exit 0
## S2 clean: xml reply resolves, tags name the reply and its fields (nested source.url included)
meta: meta verify — 1 template(s) clean.
meta: meta verify — not run: schema (--db <url>), codegen (--codegen), deps (--deps), replay (--replay)
  templates,true,true
exit=0
Evidence: S3 — Rust cargo-meta verify --templates: clean, Jinja refusal, ERR_RESPONSE_UNRESOLVED, bare verify runs the gate

cargo meta verify — 1 template(s) clean. error: [AnswerPrompt] (prompt) ERR_TEMPLATE_ENGINE_UNSUPPORTED: support/answer is a Jinja template; the Rust port checks Mustache only error: [AnswerPrompt] (reply) ERR_RESPONSE_UNRESOLVED: acme::support::EmptyAnswer

## S3 clean: Mustache gate + reply check in the Rust port (previously: no template gate at all)
cargo meta verify — 1 template(s) clean.
exit=0

## S3 adversarial: Jinja body refused (renderer is Mustache-only)
error: [AnswerPrompt] (prompt) ERR_TEMPLATE_ENGINE_UNSUPPORTED: support/answer is a Jinja template; the Rust port checks Mustache only
cargo meta verify — 1 drift error(s) across 1 template(s).
exit=1

## S3 adversarial: reply type loads but has no fields (ERR_RESPONSE_UNRESOLVED, error)
error: [AnswerPrompt] (reply) ERR_RESPONSE_UNRESOLVED: acme::support::EmptyAnswer
cargo meta verify — 1 drift error(s) across 1 template(s).
exit=1

## S3 bare verify: the template gate runs beside the codegen gate (codegen drift expected in a fresh fixture)
error: generated code is out of sync with metadata.
  missing: generated/meta_support/Cargo.toml
  missing: generated/meta_support/rustfmt.toml
  missing: generated/meta_support/src/lib.rs
  missing: generated/meta_support/src/pattern.rs
  missing: generated/meta_support/src/validation.rs
  missing: generated/meta_support/src/wire.rs
  missing: generated/acme_support/Cargo.toml
  missing: generated/acme_support/rustfmt.toml
  missing: generated/acme_support/src/support_request.rs
  missing: generated/acme_support/src/support_answer.rs
  missing: generated/acme_support/src/lib.rs
regenerate (cargo meta gen) and commit the result.
cargo meta verify — 1 template(s) clean.
exit=1 (1 = codegen drift, no gen ran; template gate reported clean)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ server/python/src/metaobjects/cli.py:612 - Python _load_collection_result: the new reference_nodes assignment had been inserted between the ADR-0058 naming comment and result.root.naming, so that comment described the wrong lines. Moved the reference block above the comment and gave it its own one-line comment. No behaviour change.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
meta gen (TypeScript CLI) with a reference: true source: the prompt's @responseRef resolves against the reply types another run owns, no code is emitted for those reference nodes, the local prompt s… ✅ pass live local run evidence (not published)
meta verify --templates (TypeScript CLI) reply check: a resolving xml reply with tags naming the reply and its nested fields passes clean; a @responseRef whose reply type has no readable field fails t… ✅ pass live local run evidence (not published)
Rust parity: cargo-meta meta verify --templates on a disposable fixture runs the previously-absent template gate with the reply check (clean pass; ERR_RESPONSE_UNRESOLVED exit 1), refuses a Jinja body… ✅ pass live local run evidence (not published)
  • scripts/ci-local.sh --affected --strict-toolchains
  • scripts/ci-local.sh --affected --strict-toolchains — configured broad regression, already ran green at the target commit (baseline); no re-run needed since this turn changed no files
  • Scenario 1 (live): bun server/typescript/packages/cli/dist/bin/meta.js gen in a disposable fixture — control without reference: true refused with ERR_INVALID_TEMPLATE; with { &#34;path&#34;: &#34;metaobjects/replies&#34;, &#34;reference&#34;: true } gen wrote only SupportRequest.ts + SupportAnswerPrompt.response.ts (parser imports ./SupportAnswer.js, the file the owning run generates); guard run with the prompt declared only in the reference source refused with ERR_REFERENCE_SOURCE_TEMPLATE
  • Scenario 2 (live): bun …/dist/bin/meta.js verify --templates in a disposable fixture — clean xml reply with tags naming the reply and nested source.url exits 0 clean; @responseRef pointed at a fieldless EmptyAnswer exits 1 with [SupportAnswerPrompt] (reply) ERR_RESPONSE_UNRESOLVED; @requiredTags naming answer/confidence prints both ERR_RESPONSE_TAG_UNDECLARED warnings and exits 0
  • Scenario 3 (live): server/rust/target/debug/cargo-meta meta verify --templates in a disposable fixture — clean Mustache prompt with @responseRef exits 0
  • Scenario 3 adversarial (live): a .jinja body refused with ERR_TEMPLATE_ENGINE_UNSUPPORTED (exit 1); @responseRef at a fieldless reply type reports [AnswerPrompt] (reply) ERR_RESPONSE_UNRESOLVED (exit 1); bare cargo-meta meta verify runs the template gate beside the codegen gate (cargo meta verify — 1 template(s) clean. alongside the codegen-drift errors of a never-generated fixture)
  • cargo build -p metaobjects-cli in server/rust — rebuilt the CLI binary before driving it (finished, incremental, warm from the baseline run)
🔧 **Document** - 1 issue found → auto-fixed ✅
  • ℹ️ docs/features/migrations-and-drift.md:767 - Out-of-scope follow-up: the per-port verify table in migrations-and-drift.md ("Drift verify commands per port") and the "Port status (staged per ADR-0021)" paragraph in docs/features/cli.md enumerate the ports' verify gates but omit Rust entirely, and the migrations-and-drift.md prose claims a bare verify runs "the same default gate set in every port" including the requirement ledger — Rust has no requirement gate (docs/ports/rust.md says so). This incompleteness predates the branch, but the branch gave Rust verify --templates, making the two stale-by-omission spots more visible. Adding a Rust row to the table and qualifying the "every port" sentence is a small follow-up I left undone to avoid expanding unrelated sections.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Validation: one no-mistakes run (review, test, document, lint), with one Document-step fix: Rust was added to the per-port verify docs.

A prompt's reply type owned by another generator run could not be used:
the reply types loaded in a separate tree so @responseRef did not resolve,
merging them in generated every reply type a second time, and the template
gate never read @responseRef.

- A `sources` entry may carry `"reference": true` (Maven:
  `<loader><referenceSources>`). Its files load into the same tree, so every
  reference resolves; a node declared only there is a reference node and no
  generator emits it. A local prompt's parser, fragment and extractor still
  emit and name the reply type as usual. A template declared only in a
  reference source is refused (ERR_REFERENCE_SOURCE_TEMPLATE).
- The template gate reports ERR_RESPONSE_UNRESOLVED (error) for a reply with
  no readable field and ERR_RESPONSE_TAG_UNDECLARED (warning) for an xml
  prompt's @requiredTags tag the reply type does not declare.

TypeScript (reference), Java, Kotlin, C#, Python and Rust (loader, config
and codegen selection; Rust ships no template gate). New corpora
fixtures/reference-source-conformance/ and fixtures/response-verify-conformance/,
plus two source-resolution cases.
…lify fixes

- Rust gains `verify --templates` (and runs it in a bare `verify`): the
  engine-level Mustache verify (all 45 verify-conformance cases), the CLI gate
  over every template body, and the @responseRef reply check
  (response-verify-conformance, 7 cases).
- Java: a pom <referenceSources> is kept when the pom names no ordinary
  sources; the reference-only template refusal runs inside the load, so every
  Java entry point refuses it; the neutral collection resolves once per run.
- TS: name reference sources, not `scope`, when they leave nothing to generate.
- Python counts checked templates the way TypeScript does.
- Docs: a reference source is a codegen setting; the node stays in the
  expected schema and the requirement ledger.
- Rust reuses its shared constants and helpers, computes the reference set
  once at load, and probes each template body once.
@dmealing
dmealing merged commit ba3646d into main Nov 25, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-reply-type-c0 branch November 25, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant